/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package music.types;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Toolkit;
import music.SpacingOptions;
import music.Staff;
import music.global.CharacterMap;

/**
 *
 * @author TJ
 */
public enum BarlineType {
    END_REPEAT((char)0xF094),START_REPEAT((char)0xF092),FINAL((char)0xF094),DOUBLE((char)0xf093),NORMAL((char)0xf093),NONE((char)0);
    private char ch;
    BarlineType(char c) {ch=c;}
    
    public String getSymbol(){return "";}
    public int renderBarline(Graphics g,SpacingOptions s, int x, int bottomLine){
        FontMetrics m=Toolkit.getDefaultToolkit().getFontMetrics(s.getRenderFont("OpusSpecial"));
        Font oldfont=g.getFont();
        g.setFont(m.getFont());
        if(ch==0){return 0;}
        int wid=CharacterMap.getWidth(ch, s.getRenderFont());
        String render=ch+"";
        switch(this) {
            case END_REPEAT:
                g.drawString(""+(char)0xf0AB, x, bottomLine-(s.getLineSpacing()+s.getLineSpacing()/2));
                g.drawString(""+(char)0xf0AB, x, bottomLine-(2*s.getLineSpacing()+s.getLineSpacing()/2));
                int addW=CharacterMap.getWidth(' ', s.getRenderFont());
                addW+=CharacterMap.getWidth((char)0xf095, s.getRenderFont());
                g.drawString(""+ch, x+addW/2, bottomLine-2*s.getLineSpacing()+1);
                return wid+addW;
            case START_REPEAT:
                g.drawString(render+(char)ch, x, s.getLineSpacing()+s.getLineSpacing()/2);
                int addWid=CharacterMap.getWidth(' ', s.getRenderFont());
                g.drawString(""+(char)0xf0AB, x+addWid/2, s.getLineSpacing()+s.getLineSpacing()/2);
                g.drawString(""+(char)0xf0AB, x+addWid/2, 2*s.getLineSpacing()+s.getLineSpacing()/2);
                addWid+=CharacterMap.getWidth((char)0xf095, s.getRenderFont());
                
                return wid+addWid;
            case DOUBLE:
                g.drawString(""+ch, x, bottomLine-2*s.getLineSpacing()+1);
                int spacewid=CharacterMap.getWidth(' ', s.getRenderFont());
                g.drawString(""+ch, x+spacewid, bottomLine-2*s.getLineSpacing()+1);
                wid+=CharacterMap.getWidth(ch, s.getRenderFont())+spacewid;
                return wid;
        }
        g.drawString(render, x, bottomLine-2*s.getLineSpacing()+1);
        g.setFont(oldfont);
        return wid;
    }
    public int getWidth(SpacingOptions s) {
        FontMetrics m=Toolkit.getDefaultToolkit().getFontMetrics(s.getRenderFont("OpusSpecial"));
        if(ch==0){return 0;}
        int wid=CharacterMap.getWidth(ch, s.getRenderFont());
        String render=ch+"";
        switch(this) {
            case END_REPEAT:
                int addW=CharacterMap.getWidth(' ', s.getRenderFont());
                addW+=CharacterMap.getWidth((char)0xf095, s.getRenderFont());
                return wid+addW;
            case START_REPEAT:
                int addWid=CharacterMap.getWidth(' ', s.getRenderFont());
                addWid+=CharacterMap.getWidth((char)0xf095, s.getRenderFont());
                
                return wid+addWid;
            case DOUBLE:
                int spacewid=CharacterMap.getWidth(' ', s.getRenderFont());
                wid+=CharacterMap.getWidth(ch, s.getRenderFont())+spacewid;
                return wid;
        }
        return wid;
    }
}
